package com.dididoctor.patient.Activity.Usercentre.Combo;

import android.view.View;
import android.widget.AbsListView;

import com.dididoctor.patient.Activity.ConstantValue;
import com.dididoctor.patient.MV.EduActivity;
import com.dididoctor.patient.R;
import com.dididoctor.patient.Ui.customlistview.OnRefreshListener;
import com.dididoctor.patient.Ui.customlistview.RefreshListView;
import com.dididoctor.patient.Utils.MyToast;
import com.dididoctor.patient.Utils.Util;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： ComboActivity
 * @包名称： com.dididoctor.patient.Activity.Usercentre.Combo
 * @创建人： zhanjunjie
 * @创建时间：2016/4/6 13:26
 * @修改人：
 * @修改时间：2016/4/6 13:26
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class ComboActivity extends EduActivity implements ComboView {
    private RefreshListView listview;
    private ComboAdapter adapter;
    private ComboPresenter comboPresenter;
    private List<ComboBean> comboBeans = new ArrayList<>();
    private int pageIndex = 1;

    @Override
    public void init() {
        setText(R.id.tv_title, "我的套餐");
        listview = (RefreshListView) findViewById(R.id.listview);
        adapter = new ComboAdapter(this, comboBeans);
        listview.setAdapter(adapter);
        listview.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onPullDownRefresh() {
                pageIndex = 1;
                comboPresenter.getcombo(pageIndex);
            }

            @Override
            public void onLoadMoring() {
                pageIndex++;
                comboPresenter.getcombo(pageIndex);
            }

            @Override
            public void onScrollListener(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });
        comboPresenter = new ComboPresenter(this, this);
        comboPresenter.getcombo(pageIndex);
    }

    @Override
    public void onClickEvent(View view) {

    }

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_combo);
    }

    @Override
    public void getComboSucced(List<ComboBean> comboBeans) {
        if (!Util.isEmpty(comboBeans)) { //如果获得的数据不为空
            if (pageIndex == 1) {
                adapter.setData(comboBeans);
                listview.onRefreshFinish();
            }else{
                adapter.addData(comboBeans);
                if(comboBeans.size()< ConstantValue.LOAD_MESSAGE_COUNT){
                    listview.showNoMoreData();
                }else{
                    listview.hideNoMoreData();
                }
            }
        } else {//为空
            if (pageIndex == 1) {
                listview.onRefreshFinish();
            }else{
                listview.showNoMoreData();
                adapter.notifyDataSetChanged();
            }
        }

    }

    @Override
    public void getCombofail() {
        listview.onRefreshFinish();
        showToastMessage("您的网络异常请稍候再试！");
    }
}
